﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Way.Page;

namespace Acc.Manage.Report_SF_aspx
{
    public partial class WarehouseView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        // 需要标识为WebMethod             
        [System.Web.Services.WebMethod]
        public static string GetWarehouseView(string strHangCode)
        {
            string strSql = "select A.Code,A.WAREHOUSENAME,A.ID,B.Code AS materials from (";
            //--货位
            strSql += " select * from Acc_WMS_WareHouse where PARENTID in (";
            //--列
            strSql += " select ID from Acc_WMS_WareHouse where PARENTID in (";
            //--行
            strSql += " select ID from Acc_WMS_WareHouse where Code='" + strHangCode + "')) and len(code)=8  ";
            strSql += " ) A left join Acc_WMS_StockInfo_Materials B on A.ID=B.DEPOTWBS";
            strSql += " order by SUBSTRING(A.Code,8,1) desc,SUBSTRING(A.Code,5,2)";
            DataTable dt = SqlHelper.ExeAll(strSql);
            //货位编码
            string strWarehouseCode = "";
            //货位名称
            string strWarehouseName = "";
            //产品ID
            string strMaterials = "";
            //返回HTML
            string strReturn = "<tr>";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                strWarehouseCode=dt.Rows[i]["Code"].ToString();
                strWarehouseName=dt.Rows[i]["WAREHOUSENAME"].ToString();
                strMaterials=dt.Rows[i]["materials"].ToString();
                if (i != 0)
                {
                    if (dt.Rows[i - 1]["Code"].ToString().Substring(7, 1) != strWarehouseCode.Substring(7, 1))
                        strReturn += "</tr>";
                }
                strReturn += "<td>";
                if (!string.IsNullOrEmpty(strMaterials))
                {
                    DataTable dtMaterial = SqlHelper.ExeAll("select Code,FNAME from Acc_Bus_BusinessCommodity where ID=" + strMaterials);
                    //产品编码
                    string strMaterialCode = "";
                    //产品名称
                    string strMaterialFname = "";
                    //库存数量
                    string strKCNum = "";
                    if (dtMaterial.Rows.Count > 0)
                    {
                        strMaterialCode = dtMaterial.Rows[0]["Code"].ToString();
                        strMaterialFname = dtMaterial.Rows[0]["FNAME"].ToString();
                        strKCNum = SqlHelper.ExeAll("select NUM from Acc_WMS_StockInfo_Materials where Code='" + strMaterials + "'").Rows[0]["NUM"].ToString();
                    }
                    strReturn += "<a onclick=\"return click_a('" + strWarehouseCode + "')\" style=\"cursor: pointer;\">";
                    strReturn += "<div class=\"divcss2\" id=\"" + strWarehouseCode + "\">";
                    strReturn += strWarehouseCode + "</br>" + strMaterialFname + "</br>数量：" + strKCNum;
                    strReturn += "</div></a></td>";
                }
                else
                    strReturn += "<div class=\"divcss1\">" + strWarehouseCode + "</div></td>";
            }
            strReturn += "</tr>";
            return strReturn;
        }
        // 需要标识为WebMethod             
        [System.Web.Services.WebMethod]
        public static string GetWarehouseItems(string strWarehouseCode)
        {
            string strSql = "select B.Code as DepotCode,C.Code as Mcode,C.FNAME,A.LASTINTIME,D.PORTNO PortCode,A.NUM from Acc_WMS_StockInfo_Materials A left join Acc_WMS_WareHouse B on A.DEPOTWBS=B.ID";
            strSql += " left join Acc_Bus_BusinessCommodity C on A.Code=C.ID";
            strSql += " left join Acc_WMS_Ports D on A.PORTCODE=D.ID where B.Code='" + strWarehouseCode + "'";
            DataTable dt = SqlHelper.ExeAll(strSql);
            //货位编码
            string strDepotCode = "";
            //产品编码
            string strMcode = "";
            //产品名称
            string strFNAME = "";
            //入库日期
            string strLASTINTIME = "";
            //托盘编码
            string strPortCode = "";
            //数量
            string strNUM = "";
            //返回HTML
            string strReturn = "异常：无数据！";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                strReturn = "";
                strDepotCode = dt.Rows[0]["DepotCode"].ToString();
                strMcode = dt.Rows[0]["Mcode"].ToString();
                strFNAME = dt.Rows[0]["FNAME"].ToString();
                strLASTINTIME = dt.Rows[0]["LASTINTIME"].ToString();
                strPortCode = dt.Rows[0]["PortCode"].ToString();
                strNUM = dt.Rows[0]["NUM"].ToString();
                //string strKongGe = "                                               ";
                string strKongGe = "</br>";
                strReturn += "货位编码：" + strDepotCode + strKongGe + "产品编码：" + strMcode + strKongGe + "产品名称：" + strFNAME;
                strReturn += strKongGe + "入库日期：" + strLASTINTIME + strKongGe + "托盘编码：" + strPortCode + strKongGe + "数量：" + strNUM;
            }
            return strReturn;
        }
        // 需要标识为WebMethod             
        [System.Web.Services.WebMethod]
        public static string GetWarehouseHangItems(string strWarehouseID)
        {
            string strSql = "select Code from Acc_WMS_WareHouse  where WHTYPE='1' and PARENTID='" + strWarehouseID + "' and Code not in ('01960000','01970000','01980000','01990000')";
            DataTable dt = SqlHelper.ExeAll(strSql);
            //货位编码
            string strHangCode = "";
            //返回HTML
            string strReturn = "异常：无数据！";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (i == 0)
                    strReturn = "";
                if (i.ToString().Substring(i.ToString().Length - 1, 1) == "0")
                    strReturn += "</br>";
                strHangCode = dt.Rows[i]["Code"].ToString();
                strReturn += "&nbsp; <a onclick=\"return change('" + strHangCode + "')\" style=\"cursor: pointer\" id=\"" + strHangCode + "\">" + strHangCode.Substring(0, 4) + "-存储区" + strHangCode.Substring(2, 2) + "行</a>";
            }
            return strReturn;
        }
    }
}